package nl.unimaas.group11.project1_3.graphics;

import java.awt.Button;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;

import nl.unimaas.group11.project1_3.Listener.Listener2dbutton;
import nl.unimaas.group11.project1_3.algo.DataProcessor;

public class RightPane extends JPanel {
	private static final long serialVersionUID = 1L;

	public static Button twoDButton;

	

	public RightPane() {
		setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
		setPreferredSize(new Dimension(200, 600));
		setBackground(Render.MEDIUM_GREY_COLOR);
		
		setForeground(Color.black);
		
	}

	public void paintComponent(Graphics og) {
		super.paintComponent(og);

			setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
			setPreferredSize(new Dimension(200, 600));
			setBackground(Render.DARK_GREY_COLOR);
			setForeground(Color.black);
			TitledBorder resultsBorder = new TitledBorder(new EtchedBorder(), "Results Window", TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION);
			resultsBorder.setTitleColor(Render.RIGHT_PANE_TITLE_COLOR);


			add(addImage("res/images/legend.gif", Render.DARK_GREY_COLOR));

			JPanel resultsPanel = new JPanel();
			resultsPanel.setBackground(Render.DARK_GREY_COLOR);
			resultsPanel.setBorder(resultsBorder);
			//resultsPanel.setSize(new Dimension(200, 300));
			
			twoDButton=new Button("Show Result in 2D");
			twoDButton.addActionListener(new Listener2dbutton());
			resultsPanel.add(decorateButton(twoDButton));

			JTextArea info = new JTextArea("");
			info.setMinimumSize(new Dimension(200, 240));
			info.setAlignmentX(CENTER_ALIGNMENT);
			info.setAlignmentY(LEFT_ALIGNMENT);

			info.append("Container X: "+DataProcessor.containerX);
			info.append("\nContainer Y: "+DataProcessor.containerY);
			info.append("\nContainer Z: "+DataProcessor.containerZ);

			if(!DataProcessor.pents){
			info.append("\n\nValue of A: " + DataProcessor.valueA);
			info.append("\nValue of B: " +  DataProcessor.valueB);
			info.append("\nValue of C: " +  DataProcessor.valueC);
			
			info.append("\n\nValue of container: "+ DataProcessor.maxValue);
			}
			info.append("\nAlgorithm ran in: "+ DataProcessor.solutionTime+" ms");
			info.append("\n% of container filled: "+DataProcessor.percent+"%");
			

			info.setBackground(Render.DARK_GREY_COLOR);
			info.setForeground(Color.WHITE);



			
			resultsPanel.add(info);

			add(resultsPanel);

			add(addImage("res/images/group11.gif", Render.DARK_GREY_COLOR));
			
			validate();
		
	}

	private JPanel addImage(String path, Color color) {

		JPanel imagePanel = new JPanel();
		imagePanel.setBackground(color);

		BufferedImage myPicture;
		try {
			myPicture = ImageIO.read(new File(path));
			JLabel picLabel = new JLabel(new ImageIcon(myPicture), SwingConstants.LEFT);

			imagePanel.add(picLabel);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return imagePanel;
	}
	private Button decorateButton(Button b) {
		b.setBackground(Render.LIGHT_GREY_COLOR);
		b.setForeground(Color.BLACK);
		return b;
	}

}